package com.sctvcloud.dongqu.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.iflytek.cloud.thirdparty.V;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.ListUtils;
import com.ruihang.generalibrary.utils.UrlUtils;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.application.Constances;
import com.sctvcloud.dongqu.beans.HomeListItem;
import com.sctvcloud.dongqu.beans.LinkItem;
import com.sctvcloud.dongqu.ui.activities.GovernmentCenterActivity;
import com.sctvcloud.dongqu.ui.activities.H5NormalActivity;
import com.sctvcloud.dongqu.ui.util.IListShowData;
import com.sctvcloud.dongqu.ui.utils.GlideCircleTransform;
import com.sctvcloud.dongqu.ui.utils.GlideUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 政务大厅
 */
public class GovMentHolder extends BaseAbsHolder<HomeListItem> implements View.OnClickListener {

    @BindView(R.id.item_more)
    protected CustomFontTextView itemMore;

    @BindView(R.id.li_1)
    protected LinearLayout li_1;
    @BindView(R.id.li_2)
    protected LinearLayout li_2;
    @BindView(R.id.li_3)
    protected LinearLayout li_3;
    @BindView(R.id.li_4)
    protected LinearLayout li_4;

    @BindView(R.id.img_1)
    protected ImageView img_1;
    @BindView(R.id.item_title_1)
    protected CustomFontTextView item_title_1;

    @BindView(R.id.img_2)
    protected ImageView img_2;
    @BindView(R.id.item_title_2)
    protected CustomFontTextView item_title_2;

    @BindView(R.id.img_3)
    protected ImageView img_3;
    @BindView(R.id.item_title_3)
    protected CustomFontTextView item_title_3;

    @BindView(R.id.img_4)
    protected ImageView img_4;
    @BindView(R.id.item_title_4)
    protected CustomFontTextView item_title_4;

    private HomeListItem item;

    public GovMentHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
        li_1.setOnClickListener(this);
        li_2.setOnClickListener(this);
        li_3.setOnClickListener(this);
        li_4.setOnClickListener(this);
        itemMore.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(HomeListItem item) {
        this.item = item;
        if (null != item && ListUtils.isListValued(item.getLinkItemList())) {
            if (item.getLinkItemList().size() >= 1) {
                li_1.setVisibility(View.VISIBLE);
                GlideUtil.getGlideWith11CircleCenterCrop(context, item.getLinkItemList().get(0).getImage()).into(img_1);
                item_title_1.setText(item.getLinkItemList().get(0).getName());
                if (item.getLinkItemList().size() >= 2) {
                    li_2.setVisibility(View.VISIBLE);
                    GlideUtil.getGlideWith11CircleCenterCrop(context, item.getLinkItemList().get(1).getImage()).into(img_2);
                    item_title_2.setText(item.getLinkItemList().get(1).getName());
                    if (item.getLinkItemList().size() >= 3) {
                        li_3.setVisibility(View.VISIBLE);
                        GlideUtil.getGlideWith11CircleCenterCrop(context, item.getLinkItemList().get(2).getImage()).into(img_3);
                        item_title_3.setText(item.getLinkItemList().get(2).getName());
                        if (item.getLinkItemList().size() >= 4) {
                            li_4.setVisibility(View.VISIBLE);
                            GlideUtil.getGlideWith11CircleCenterCrop(context, item.getLinkItemList().get(3).getImage()).into(img_4);
                            item_title_4.setText(item.getLinkItemList().get(3).getName());
                            if (item.getLinkItemList().size() > 4) {
                                itemMore.setVisibility(View.VISIBLE);
                            }
                        }
                    }
                }
                itemMore.setVisibility(View.VISIBLE);
            }

        }
    }

    @Override
    public void onClick(View v) {
        if (null != item) {
            List<LinkItem> list = item.getLinkItemList();
            if (v.getId() == R.id.li_1) {
                if (ListUtils.isListValued(list) && list.size() > 0) {
                    Intent intent = new Intent(context, H5NormalActivity.class);
                    intent.putExtra(H5NormalActivity.EX_TITLE, list.get(0).getName());
                    intent.putExtra(H5NormalActivity.EX_HTML, list.get(0).getLink());
                    context.startActivity(intent);
                }
            } else if (v.getId() == R.id.li_2) {
                if (ListUtils.isListValued(list) && list.size() > 1) {
                    Intent intent = new Intent(context, H5NormalActivity.class);
                    intent.putExtra(H5NormalActivity.EX_TITLE, list.get(1).getName());
                    intent.putExtra(H5NormalActivity.EX_HTML, list.get(1).getLink());
                    context.startActivity(intent);
                }
            } else if (v.getId() == R.id.li_3) {
                if (ListUtils.isListValued(list) && list.size() > 2) {
                    Intent intent = new Intent(context, H5NormalActivity.class);
                    intent.putExtra(H5NormalActivity.EX_TITLE, list.get(2).getName());
                    intent.putExtra(H5NormalActivity.EX_HTML, list.get(2).getLink());
                    context.startActivity(intent);
                }
            } else if (v.getId() == R.id.li_4) {
                if (ListUtils.isListValued(list) && list.size() > 3) {
                    Intent intent = new Intent(context, H5NormalActivity.class);
                    intent.putExtra(H5NormalActivity.EX_TITLE, list.get(3).getName());
                    intent.putExtra(H5NormalActivity.EX_HTML, list.get(3).getLink());
                    context.startActivity(intent);
                }
            } else if (v.getId() == R.id.item_more) {
                Intent intent = new Intent(context, GovernmentCenterActivity.class);
                intent.putExtra(GovernmentCenterActivity.GOV_CENTER_URL, item.getSubUrl());
                context.startActivity(intent);
            }

        }


    }


}
